//
//  SISSMinePassengerCooperationCell.m
//  SISSAPP
//
//  Created by 优房网 on 2017/5/24.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSMinePassengerCooperationCell.h"
#import <SDWebImage/UIImageView+WebCache.h>

@interface SISSMinePassengerCooperationCell ()

@property (weak, nonatomic) IBOutlet UIImageView *iconImageView;
@property (weak, nonatomic) IBOutlet UILabel *agencyNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *companyLabel;
@property (weak, nonatomic) IBOutlet UILabel *buyerNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *regionAreaHouseTypeLabel;
@property (weak, nonatomic) IBOutlet UILabel *tagLabel;
@property (weak, nonatomic) IBOutlet UILabel *ownerPercentLabel;
@property (weak, nonatomic) IBOutlet UILabel *partnerPercentLabel;

@end
@implementation SISSMinePassengerCooperationCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setPassengerCooperationModel:(SISSPassengerCooperationModel *)passengerCooperationModel {
    
    _passengerCooperationModel = passengerCooperationModel;
    
    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:passengerCooperationModel.portrait] placeholderImage:[UIImage imageNamed:@"头像"]];
    self.agencyNameLabel.text = passengerCooperationModel.name;
    self.companyLabel.text = passengerCooperationModel.shortName.length ? passengerCooperationModel.shortName : passengerCooperationModel.organName;
    
    // 根据身份证判断显示 先生、女士
    NSString *fisrtName = [passengerCooperationModel.buyerName substringToIndex:1];
    NSInteger idNum = [[passengerCooperationModel.idNumber substringWithRange:NSMakeRange(passengerCooperationModel.idNumber.length - 2, 1)] integerValue];
    
    NSString *genderStr = (idNum % 2) == 0 ? @"女士" : @"先生";
    self.buyerNameLabel.text = [NSString stringWithFormat:@"%@%@",fisrtName,genderStr];
    self.regionAreaHouseTypeLabel.text = [NSString stringWithFormat:@"%0.f-%0.f万 | %@-%@ | %@",passengerCooperationModel.minPrice,passengerCooperationModel.maxPrice,passengerCooperationModel.region,passengerCooperationModel.regionDetail,passengerCooperationModel.houseType];
    
    NSString *tagStr;
    UIColor *tagColor;
    switch (passengerCooperationModel.request_status) {
        case 0:
            tagStr = @"待确认";
//            0xAEC1D9
            tagColor = COLOR(0xFF1F1D);
            break;
            
        case 1:
            tagStr = @"已确认";
            tagColor = COLOR(0xff334f);
            break;
            
        case 2:
            tagStr = @"已拒绝";
            tagColor = COLOR(0xFF1F1D);
            break;
            
        default:
            break;
    }
    
    self.tagLabel.textColor = tagColor;
    self.tagLabel.text = tagStr;
    
    self.ownerPercentLabel.text = [NSString stringWithFormat:@"%0.f%@",passengerCooperationModel.commission_rate,@"%"];
    self.partnerPercentLabel.text = [NSString stringWithFormat:@"%0.f%@",100 -passengerCooperationModel.commission_rate,@"%"];
}

/**
 联系按钮点击事件
 */
- (IBAction)contactButtonClickAction:(UIButton *)sender {
    
    if ([self.delegate respondsToSelector:@selector(passengerCooperationCell:clickContactButton:)]) {
        
        [self.delegate passengerCooperationCell:self clickContactButton:sender];
    }
}


@end
